<?php
namespace addons\TfFutures\api\controllers;

use \common\models\member\Member;
use Yii;
use common\helpers\ResultDataHelper;
use api\controllers\OnAuthController;


class MyGroupController extends OnAuthController
{
    public $modelClass = Member::class;

    /**
    * 我的团队
    * @return string
    */
    public function actionList()
    {
        if (!Yii::$app->request->isGet) {
            return ResultDataHelper::api(304,'access done!');
        }
        $uid = Yii::$app->user->identity->member_id;
        if (empty($uid)) {
            return ResultDataHelper::api(422,'用户id不能为空');
        }

        $model = $this->modelClass::find()->where(['pid'=>$uid])->asArray()->all();
        foreach ($model as $k=>$v) {
            $model[$k]['child'] = $this->modelClass::find()->where(['pid'=>$v['id']])->asArray()->all();
        }
        return ResultDataHelper::api(200,'ok',$model);
    }

}